﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

//与数据库表对应的类
// 1. 测试项目定义
public class TestProject
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public virtual ICollection<ProjectParameter> Parameters { get; set; } = new List<ProjectParameter>();
}
public class User
{
    [Key]
    public int Id { get; set; }
    public string Username { get; set; } = string.Empty;
    public string PasswordHash { get; set; } = string.Empty;
    public string? FullName { get; set; }
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    // 导航属性：一个用户可以有多个测试模板
    public virtual ICollection<TestTemplate> TestTemplates { get; set; } = new List<TestTemplate>();
}

// 2. 项目参数定义
public class ProjectParameter
{
    [Key]
    public int Id { get; set; }
    public int TestProjectId { get; set; }
    public string Name { get; set; } = string.Empty;
    public string DataType { get; set; } = "string";
    public bool IsAdjustable { get; set; }
    public string? DefaultValue { get; set; }

    [ForeignKey("TestProjectId")]
    public virtual TestProject TestProject { get; set; } = null!;
}

// 3. 测试模板
public class TestTemplate
{
    [Key]
    public int Id { get; set; }

    // 新增属性，用于关联用户
    public int UserId { get; set; }

    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    // 新增导航属性
    [ForeignKey("UserId")]
    public virtual User User { get; set; } = null!;

    public virtual ICollection<TemplateStep> Steps { get; set; } = new List<TemplateStep>();
}

// 4. 模板中的步骤
public class TemplateStep
{
    [Key]
    public int Id { get; set; }
    public int TestTemplateId { get; set; }
    public int TestProjectId { get; set; }
    public int StepOrder { get; set; }

    [ForeignKey("TestTemplateId")]
    public virtual TestTemplate TestTemplate { get; set; } = null!;

    [ForeignKey("TestProjectId")]
    public virtual TestProject TestProject { get; set; } = null!;

    public virtual ICollection<StepParameterValue> ParameterValues { get; set; } = new List<StepParameterValue>();
}

// 5. 步骤中设置的参数值
public class StepParameterValue
{
    [Key]
    public int Id { get; set; }
    public int TemplateStepId { get; set; }
    public int ProjectParameterId { get; set; }
    public string Value { get; set; } = string.Empty;

    [ForeignKey("TemplateStepId")]
    public virtual TemplateStep TemplateStep { get; set; } = null!;

    [ForeignKey("ProjectParameterId")]
    public virtual ProjectParameter ProjectParameter { get; set; } = null!;
}